package com.ks.app.admin.action;

import java.util.List;
import javax.annotation.Resource;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import com.ks.app.ad.service.KsadService;
import com.ks.app.admin.service.KsVersionService;
import com.ks.app.admin.service.KsresolutionService;

@ParentPackage("json-default")
@Namespace("")
@Results( { @Result(type = "json") })
public class JsonAction extends BaseAction {
	

	private static final long serialVersionUID = -641222340254483415L;
	
	@SuppressWarnings("unchecked")
	private List waplist;
	private String str;
	@Resource
	private KsadService ksadService;
	@Resource
	private KsresolutionService ksresolutionService;
	@Resource
	private KsVersionService ksVersionService;
	
//	$.getJSON("/admin/json/kswap?uname=" + str.id+"&idvalue="+str.value+"&rnd="+Math.random(), function(data) {
//		   if(data.str=='Y'){
//		  		alert("修改成功");
//		 	}
//		 	if(data.str=='N'){
//		 	 alert("修改失败");
//		 		}
//			}); js 调用方式，参数根据需要自带  返回List结果集请查阅资源
	@Action("/admin/json/isexsistAdUrl")//通过$.getJSON访问返回所需值,在访问的时候带上一个随机参数rnd=随机数，防止提交不到后台的情况
	public String isexsistAdUrl()//判断广告是否重复
	{
//		waplist=""; 可以返回list或者返回String
//		str="需要值";
		String url=request.getParameter("url")==null?"":request.getParameter("url").toString().trim();
		String uid=request.getParameter("uid")==null?"":request.getParameter("uid").toString().trim();
		
		//testService.getAll(uname);
		waplist=ksadService.GetKsAdByUrl(url,uid);
		if(waplist.size()>0)
		{
			str="Y";
		}
		else
		{
			str="N";
		}
		return SUCCESS;//固定不变
	}	
	@Action("/admin/json/isexsistResolution")//通过$.getJSON访问返回所需值,在访问的时候带上一个随机参数rnd=随机数，防止提交不到后台的情况
	public String isexsistResolution() //判断分辨率数据是否重复
	{
//		waplist=""; 可以返回list或者返回String
//		str="需要值";
		String resolution=request.getParameter("resolution")==null?"":request.getParameter("resolution").toString().trim();
		String uid=request.getParameter("uid")==null?"":request.getParameter("uid").toString().trim();
		
		//testService.getAll(uname);
		waplist=ksresolutionService.GetKsKsResolutionByResol(resolution,uid);
		if(waplist.size()>0)
		{
			str="Y";
		}
		else
		{
			str="N";
		}
		return SUCCESS;//固定不变
	}
	@Action("/admin/json/ToCreatetxt")//通过$.getJSON访问返回所需值,在访问的时候带上一个随机参数rnd=随机数，防止提交不到后台的情况
	public String ToCreatetxt() //生成ads.txt文件  分省份
	{
		str="N";
		String uid=request.getParameter("id")==null?"":request.getParameter("id").toString().trim();
		String username=request.getSession().getAttribute("userinfo").toString().trim();
		str=ksadService.ToCreatetxt(uid,username);
		/*if(waplist.size()>0)
		{
			str="Y";
		}
		else
		{
			str="N";
		}*/
		return SUCCESS;//固定不变
	}
	
	
	@Action("/admin/json/isexsistApkversion")
	public String isexsistApkversion()//判断APK版本是否重复
	{
		str="N";
		String ver=request.getParameter("ver")==null?"":request.getParameter("ver").toString().trim();
		String vtype=request.getParameter("vt")==null?"":request.getParameter("vt").toString().trim();
		
		//testService.getAll(uname);
		str=ksVersionService.isexsistVersion(vtype, "", ver);		
		return SUCCESS;//固定不变
	}	
	
	public String getStr() {
		return str;
	}

	public void setStr(String str) {
		this.str = str;
	}


	@SuppressWarnings("unchecked")
	public List getWaplist() {
		return waplist;
	}

	@SuppressWarnings("unchecked")
	public void setWaplist(List waplist) {
		this.waplist = waplist;
	}
}
